package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckItemService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: XuZhen
 * @Date: 上午 10:04 2021/2/25 0025
 * @Parms
 * @ReturnType:
 * @Description: 检查项分页查询
 **/
@RestController
@RequestMapping("checkitem")
@CrossOrigin
public class CheckItemController {
    @DubboReference
    private CheckItemService checkItemService;

    @GetMapping("findpage")
    //@PreAuthorize("hasAnyAuthority('CHECKITEM_QUERY')")
    public Result finaPage(QueryPageBean queryPageBean) {
        PageResult page = checkItemService.findPage(queryPageBean);
        return new Result(true, MessageConst.QUERY_CHECKITEM_SUCCESS, page);
    }

    @PostMapping("add")
    //@PreAuthorize("hasAnyAuthority('CHECKITEM_ADD')")
    public Result add(@RequestBody CheckItem checkItem) {
        checkItemService.add(checkItem);

        return new Result(true, MessageConst.ADD_CHECKITEM_SUCCESS);
    }

    @PostMapping("delete")
    //@PreAuthorize("hasAnyAuthority('CHECKITEM_DELETE')")
    public Result delete(Integer id) {
        checkItemService.delete(id);
        return new Result(true, MessageConst.DELETE_CHECKITEM_SUCCESS);
    }

    @GetMapping("findById")
    //@PreAuthorize("hasAnyAuthority('CHECKITEM_QUERY')")
    public Result findById(Integer id) {
        CheckItem checkItem = checkItemService.findById(id);
        return new Result(true, MessageConst.QUERY_CHECKITEM_SUCCESS, checkItem);
    }

    @PostMapping("edit")
    //@PreAuthorize("hasAnyAuthority('CHECKITEM_EDIT')")
    public Result edit(@RequestBody CheckItem checkItem) {
        checkItemService.edit(checkItem);
        return new Result(true, MessageConst.EDIT_CHECKITEM_SUCCESS);
    }

    @GetMapping("findAll")
//    //@PreAuthorize("hasAnyAuthority('CHECKITEM_QUERY')")
    public Result findAll() {
        List<CheckItem> all = checkItemService.findAll();
        return new Result(true, MessageConst.QUERY_CHECKITEM_SUCCESS, all);
    }
}
